package com.main.tripplanner.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.main.tripplanner.persistent.Attraction;
import com.main.tripplanner.persistent.Attraction.AttractionType;
import com.main.tripplanner.persistent.City;
import com.main.tripplanner.persistent.Country;

@Repository
public class AttractionDAO extends AbstractDAO{

	public List<Attraction> getAllAttractionsByCountryAndType(Country country,List<Integer> citiesIds, List<Integer> attractionsIds, AttractionType attractionType) {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Attraction.class);
		criteria.add(Restrictions.eq("attractionType", attractionType));
		if(!attractionsIds.isEmpty()){
			criteria.add(Restrictions.not(Restrictions.in("id", attractionsIds)));
		}
		criteria.createAlias("city", "city");
		if(!citiesIds.isEmpty()){
			criteria.add(Restrictions.not(Restrictions.in("city.id", citiesIds)));
		}
		criteria.add(Restrictions.eq("city.country", country));
		List<Attraction> resultList = criteria.list();
		return resultList;
		
	}
	
	public List<Attraction> getCityAttractions(City city, Attraction bestAttraction){
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Attraction.class);
		criteria.add(Restrictions.eq("city", city));
		criteria.add(Restrictions.ne("id", bestAttraction.getId()));
		List<Attraction> resultList = criteria.list();
		return resultList;
	}

	public Attraction getFullyInitializedAttractionById(int id) {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Attraction.class);
		criteria.add(Restrictions.eq("id", id));
		List<Attraction> resultList = criteria.list();
		if(resultList.size() == 0){
			return null;
		}
		else{
			return resultList.get(0);
		}
	}

}
